
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 11/28/2012 20:58:50
-- Generated from EDMX file: H:\proj\NthParameterSeries\Coda.Nth.Database\CodaNth.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE brett;
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_PortfolioPrice]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PriceSet] DROP CONSTRAINT [FK_PortfolioPrice];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[PriceSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PriceSet];
GO
IF OBJECT_ID(N'[dbo].[PortfolioSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PortfolioSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'PriceSet'
CREATE TABLE [dbo].[PriceSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [AsOfDate] datetime  NOT NULL,
    [Nav] decimal(18,0)  NOT NULL,
    [Ror] decimal(18,0)  NOT NULL,
    [EntryDate] datetime  NOT NULL,
    [Portfolio_Id] int  NOT NULL
);
GO

-- Creating table 'PortfolioSet'
CREATE TABLE [dbo].[PortfolioSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [InceptionDate] datetime  NOT NULL,
    [Address_City] nvarchar(max)  NOT NULL,
    [Address_Country] nvarchar(max)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'PriceSet'
ALTER TABLE [dbo].[PriceSet]
ADD CONSTRAINT [PK_PriceSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'PortfolioSet'
ALTER TABLE [dbo].[PortfolioSet]
ADD CONSTRAINT [PK_PortfolioSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Portfolio_Id] in table 'PriceSet'
ALTER TABLE [dbo].[PriceSet]
ADD CONSTRAINT [FK_PortfolioPrice]
    FOREIGN KEY ([Portfolio_Id])
    REFERENCES [dbo].[PortfolioSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PortfolioPrice'
CREATE INDEX [IX_FK_PortfolioPrice]
ON [dbo].[PriceSet]
    ([Portfolio_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------